package com.hdw.auth.service;

import com.hdw.common.vo.PaginationVO;
import org.springframework.stereotype.Service;
import com.hdw.auth.api.BaseAuthRoleService;
import com.hdw.auth.mapper.BaseAuthRoleMapper;
import com.hdw.auth.bean.model.BaseAuthRole;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * baseAuthRole服务实现类
 * Created by liujunlei on 2022/01/05.
 */
@Service
@Transactional
public class BaseAuthRoleServiceImpl implements BaseAuthRoleService{

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseAuthRoleServiceImpl.class);

    @Autowired
    private BaseAuthRoleMapper baseAuthRoleMapper;

    @Override
    public int insert(BaseAuthRole baseAuthRole) {
        return baseAuthRoleMapper.insert(baseAuthRole);
    }

    @Override
    public int insertSelective(BaseAuthRole baseAuthRole)  {
        return baseAuthRoleMapper.insertSelective(baseAuthRole);
    }

    @Override
    public int deleteById(Long idRole)  {
        return baseAuthRoleMapper.deleteByPrimaryKey(idRole);
    }

    @Override
    public int updateByIdSelective(BaseAuthRole baseAuthRole)  {

        return baseAuthRoleMapper.updateByPrimaryKeySelective(baseAuthRole);
    }

    @Override
    public int updateById(BaseAuthRole baseAuthRole)  {
        return baseAuthRoleMapper.updateByPrimaryKey(baseAuthRole);
    }

    @Override
    public BaseAuthRole getById(Long idRole)  {
        return baseAuthRoleMapper.selectByPrimaryKey(idRole);
    }

    @Override
    public List<BaseAuthRole> findByModel(BaseAuthRole baseAuthRole)  {
        return baseAuthRoleMapper.findByModel(baseAuthRole);
    }

    @Override
    public PaginationVO<BaseAuthRole> findPageByModel(BaseAuthRole baseAuthRole, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<BaseAuthRole> quesList = baseAuthRoleMapper.findByModel(baseAuthRole);
        PageInfo<BaseAuthRole> pageInfo = new PageInfo<>(quesList);
        PaginationVO<BaseAuthRole> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }


}
